package com.atguigu05.map.exer2;

import java.util.*;

/**
 * ClassName: CityMap
 * Package: com.atguigu05.map.exer2
 * Description:
 *
 * @Author BuTang
 * @Create 2023/6/7 11:45
 * @Version 1.0
 */

class CityMapTest {

    public static Map model = new HashMap();

    static {
        model.put("北京", new String[] {"北京"});
        model.put("辽宁", new String[] {"沈阳","盘锦","铁岭","丹东","大连","锦州","营口"});
        model.put("吉林", new String[] {"长春","延边","吉林","白山","白城","四平","松原"});
        model.put("河北", new String[] {"承德","沧州","邯郸","邢台","唐山","保定","石家庄"});
        model.put("河南", new String[] {"郑州","许昌","开封","洛阳","商丘","南阳","新乡"});
        model.put("山东", new String[] {"济南","青岛","日照","临沂","泰安","聊城","德州"});
    }

}
class CMT{
    public static void main(String[] args) {

        //获取省份信息
        Map map = CityMapTest.model;

        Scanner scanner = new Scanner(System.in);

        Set sf =  map.keySet();//获取key并遍历
        Iterator iterator =  sf.iterator();
        while (iterator.hasNext()){
            System.out.print(iterator.next() + "\t\t");
        }

        System.out.println("请选择你所在的省份：");

        //进行比较
        String type = scanner.next();
        if (map.containsKey(type)) {

            //用于判断
            //System.out.println("1111");

            System.out.println("请输入你所在的城市:");

            //输出城市
            String[] city = (String[]) map.get(type);
            for (Object obj:city){
                System.out.print(obj+"\t\t");
            }

            //再次比较
            type = scanner.next();
            System.out.println("你输入的城市为："+type);

            //用于标识城市是否存在
            boolean Judge = false;

            for (int i = 0; i <city.length ; i++) {
                if (city[i].equals(type) ) {
                    System.out.println("信息登记完毕");
                    Judge = true;
                    scanner.close();
                }
            }
            if (Judge==false)   throw new RuntimeException("不存在该城市");

       }
        else throw new RuntimeException("输入的省份不存在");
        scanner.close();

    }
}